﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.tutorial.chapter {
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.machines.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.controllers.startup.*;
    import net.wooga.pets.views.tutorial.*;

    public class TutorialLevel1Mediator extends TutorialMediator {

        private var _localMapping:Dictionary;

        public static var AVATAR_OFFSET_FIRST_STEPS:int = 80;
        public static var AVATAR_OFFSET_CORNER:int = 40;

        public function TutorialLevel1Mediator():void{
            this._localMapping = new Dictionary();
            this._localMapping[TutorialModel.LEVEL1_LOAD_ASSETS] = this.onLoadAssets;
            this._localMapping[TutorialModel.LEVEL1_SHOW_FIRST_PET] = this.onShowFirstPet;
            this._localMapping[TutorialModel.LEVEL1_BUILD_RECEPTION] = this.onBuildReception;
            this._localMapping[TutorialModel.LEVEL1_BUILD_WAITING_ROOM] = this.onBuildWaitingRoom;
            this._localMapping[TutorialModel.LEVEL1_BUILD_BATTERY_ROOM] = this.onBuildBatteryRoom;
            this._localMapping[TutorialModel.LEVEL1_BUILD_TREATMENT_GENERAL_ROOM] = this.onBuildGeneralTreatmentRoom;
            this._localMapping[TutorialModel.LEVEL1_BUILD_TREATMENT_GENERAL_ROOM_2] = this.onBuildGeneralTreatment2;
            this._localMapping[TutorialModel.LEVEL1_PET_ARRIVES] = this.onPetArrives;
            this._localMapping[TutorialModel.LEVEL1_CREATE_PATIENT] = this.onCreatePatient;
            this._localMapping[TutorialModel.LEVEL1_WELCOME_PATIENT] = this.onWelcomePatient;
            this._localMapping[TutorialModel.LEVEL1_PET_TO_TREATMENT] = this.onPetToTreatment;
            this._localMapping[TutorialModel.LEVEL1_CLICK_ON_SLOTMACHINE] = this.onClickOnSlotmachine;
            this._localMapping[TutorialModel.LEVEL1_CLICK_ON_BATTERY] = this.onClickBattery;
            this._localMapping[TutorialModel.LEVEL1_BATTERY_TO_TREATMENT] = this.onBatteryToTreatment;
            this._localMapping[TutorialModel.LEVEL1_WAIT_FOR_FIRST_TREATMENT] = this.onWaitForFirstTreatment;
            this._localMapping[TutorialModel.LEVEL1_RELEASE_FIRST_TREATMENT] = this.onReleaseFromFirstTreatment;
            this._localMapping[TutorialModel.LEVEL1_CURED_FIRST_PET] = this.onCuredFirstPet;
            this._localMapping[TutorialModel.LEVEL1_CLEAN] = this.onClean;
            this._localMapping[TutorialModel.LEVEL1_CLICK_ON_SECOND_PET] = this.onClickOnReception;
            this._localMapping[TutorialModel.LEVEL1_SELECT_PATIENT] = this.onSelectPatient;
            this._localMapping[TutorialModel.LEVEL1_WELCOME_PATIENT_2] = this.onWelcomePatient2;
            this._localMapping[TutorialModel.LEVEL1_WELCOME_PATIENT_3] = this.onWelcomePatient3;
            this._localMapping[TutorialModel.LEVEL1_WELCOME_PATIENT_4] = this.onWelcomePatient4;
            this._localMapping[TutorialModel.LEVEL1_PATIENT_IN_TREATMENT] = this.onPetInTreatment;
            this._localMapping[TutorialModel.LEVEL1_BOOST_PATIENT] = this.onBoostPatient;
            this._localMapping[TutorialModel.LEVEL1_BOOST_PATIENT_FINISH] = this.onBoostPatientEnd;
            this._localMapping[TutorialModel.LEVEL1_FINISH_LEVEL1_TUTORIAL] = this.onFinish;
        }
        override public function onRegister():void{
            super.onRegister();
        }
        override protected function onStateChange(_arg1:GameEvent=null):void{
            super.onStateChange(_arg1);
            var _local2:Function = this._localMapping[tutorialModel.state];
            if (_local2 != null){
                _local2();
            };
        }
        public function onLoadAssets():void{
            dispatch(new Event(EventConstants.LOAD_TUTORIAL_ASSETS));
        }
        public function onWelcome():void{
            var _local1:Point = this.getAvatarPosition(1);
            var _local2:Point = this.getAvatarPosition(2);
            var _local3:Point = new Point(((_local1.x + _local2.x) / 2), _local1.y);
            dispatch(new InfoEvent(EventConstants.MOVE_TO_POSITION, GameConstants.AVATAR_ID, [_local3]));
        }
        public function onShowFirstPet():void{
            gameViewModel.gameViewPosition = new Point((-(GameConstants.HOSPITAL_CENTER_POSITION.x) - 1), -100);
            gameViewModel.setGameScaleByIndex(GameViewModel.SCALE_2X2);
            mapEvent(EventConstants.FIRST_PET_BUBBLE_CLOSED, TutorialModel.LEVEL1_BUILD_RECEPTION);
            tutorial.showPetComponent();
            var _local1:TextFormat = new TextFormat();
            _local1.font = "MyriadProFont";
            _local1.bold = true;
            tutorial.firstPetComponent.setButtonText(languageModel.getTextByKey("global_button_ok"), _local1);
            tutorial.firstPetComponent.setMessageText(languageModel.getTextByKey("general_tutorial_firstpetpopup"), _local1);
            tutorial.firstPetComponent.addEventListener(EventConstants.OK_BUTTON_CLICK, this.onFirstPetClosed);
            tutorial.hideFocusArrow();
            tutorial.showBlockingSpotlight();
        }
        public function onBuildReception():void{
            eventMap.mapListener(eventDispatcher, EventConstants.CREATE_ROOM_VIEW, mapRoomCreated);
            tutorial.showFocusArrow(210, 230);
            tutorial.showBlockingSpotlight(250, 430, 0.7);
            var _local1:String = languageModel.getTextByKey("general_tutorial_welcome");
            sunModel.simpleMessageWithoutHide = _local1;
        }
        public function onBuildWaitingRoom():void{
            var _local1:Point = this.getAvatarPosition(1);
            dispatch(new InfoEvent(EventConstants.MOVE_TO_POSITION, GameConstants.AVATAR_ID, [_local1]));
            gameStateModel.isFacadeVisible = false;
            tutorial.showFocusArrow(480, 230);
            tutorial.showBlockingSpotlight(520, 430, 0.7);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_buildreception");
        }
        public function onBuildBatteryRoom():void{
            dispatch(new InfoEvent(EventConstants.MOVE_TO_POSITION, GameConstants.AVATAR_ID, [this.getAvatarPosition(2)]));
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"10_two_rooms_built"}));
            tutorial.showFocusArrow(310, 260, -90);
            tutorial.showBlockingSpotlight(520, 220, 0.7);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_buildwaitingroom");
        }
        public function onBuildGeneralTreatmentRoom():void{
            tutorial.showFocusArrow(40, 260, -90);
            tutorial.showBlockingSpotlight(250, 220, 0.7);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_buildbatteryroom");
        }
        public function onBuildGeneralTreatment2():void{
            eventMap.unmapListener(eventDispatcher, EventConstants.CREATE_ROOM_VIEW, mapRoomCreated);
            var _local1:Point = new Point((this.getAvatarPosition(1).x - 160), this.getAvatarPosition(1).y);
            dispatch(new InfoEvent(EventConstants.MOVE_TO_POSITION, GameConstants.AVATAR_ID, [_local1]));
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"20_four_rooms_built"}));
            tutorial.hideFocusArrow();
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            sunModel.simpleMessage = languageModel.getTextByKey("general_tutorial_buildtreatmentroom");
            triggerNewState(TutorialModel.LEVEL1_PET_ARRIVES, 2000);
        }
        public function onPetArrives():void{
            tutorial.hideFocusArrow();
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            triggerNewState(TutorialModel.LEVEL1_CREATE_PATIENT, 1);
        }
        public function onCreatePatient():void{
            mapEvent(EventConstants.ON_ARRIVAL_AT_RECEPTION, TutorialModel.LEVEL1_WELCOME_PATIENT);
            var _local1:Object = {pet_type:"bear", disease_name:"fishaccident", disease_id:13};
            dispatch(new InfoEvent(EventConstants.SELECT_PET_DATA, null, _local1));
        }
        public function onWelcomePatient():void{
            mapEvent(EventConstants.SHOW_RECEPTION_BUBBLE, TutorialModel.LEVEL1_PET_TO_TREATMENT);
            tutorial.showFocusArrow(260, 190);
            tutorial.showBlockingSpotlight(300, 400, 0.75);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_welcomepatient");
            dispatch(new Event(EventConstants.LOAD_GAME_ASSETS));
        }
        public function onPetToTreatment():void{
            mapEvent(EventConstants.HIDE_VIEW, TutorialModel.LEVEL1_CLICK_ON_SLOTMACHINE);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"30_welcome_first_pet"}));
            tutorial.hideFocusArrow();
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onClickOnSlotmachine():void{
            mapEvent(SlotMachineEvent.ON_SLOT_MACHINE_UPDATED, TutorialModel.LEVEL1_CLICK_ON_BATTERY);
            tutorial.hideFocusArrow();
            tutorial.showBlockingSpotlight(580, 220, 0.9);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_clickonslotmachine");
        }
        public function onClickBattery():void{
            dispatch(new InfoEvent(EventConstants.SHOW_MAIN_MENU_INVENTORY_ONLY, null));
            mapEvent(EventConstants.COLLECT_REWARD_ITEM, TutorialModel.LEVEL1_BATTERY_TO_TREATMENT);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"40_cl_slotmachine"}));
            tutorial.showFocusArrow(390, 315, -90);
            tutorial.showBlockingSpotlight(585, 285, 0.5);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_clickbattery");
        }
        public function onBatteryToTreatment():void{
            mapEvent(EventConstants.CHARGE_MACHINE, TutorialModel.LEVEL1_WAIT_FOR_FIRST_TREATMENT);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"50_cl_battery"}));
            gameStateModel.isFacadeVisible = false;
            tutorial.hideFocusArrow();
            tutorial.showBlockingSpotlight(300, 220, 0.8);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_batterytotreatment");
        }
        public function onWaitForFirstTreatment():void{
            mapEvent(EventConstants.ON_TREATMENT_FINISHED, TutorialModel.LEVEL1_RELEASE_FIRST_TREATMENT);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"60_cl_treat_machine"}));
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            sunModel.simpleMessage = languageModel.getTextByKey("general_tutorial_waitfortreatment");
        }
        public function onReleaseFromFirstTreatment():void{
            mapEvent(EventConstants.SHOW_VIEW, TutorialModel.LEVEL1_CURED_FIRST_PET);
            tutorial.showFocusArrow(490, 180, 90);
            tutorial.showBlockingSpotlight(300, 220, 0.8);
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_releasepet");
        }
        public function onCuredFirstPet():void{
            mapEvent(EventConstants.FIRST_PET_BUBBLE_CLOSED, TutorialModel.LEVEL1_CLEAN);
            tickModel.pause = true;
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"70_first_harvest"}));
            tutorial.showPetComponent();
            tutorial.firstPetComponent.isCured = true;
            var _local1:TextFormat = new TextFormat();
            _local1.font = "MyriadProFont";
            _local1.bold = true;
            tutorial.firstPetComponent.setButtonText(languageModel.getTextByKey("global_button_ok"), _local1);
            tutorial.firstPetComponent.setMessageText(languageModel.getTextByKey("general_tutorial_firstpetpopup2"), _local1);
            tutorial.firstPetComponent.addEventListener(EventConstants.OK_BUTTON_CLICK, this.onFirstPetClosed);
            tutorial.hideFocusArrow();
            tutorial.showBlockingSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onClean():void{
            tickModel.pause = false;
            var _local1:IRoom = IRoom(world.getRoomById("r6"));
            l(("c generalTreatmentRoom.machine.state: " + _local1.machine.state));
            if (_local1.machine.state != WorldConstants.DIRTY){
                tutorialModel.state = TutorialModel.LEVEL1_CLICK_ON_SECOND_PET;
            } else {
                mapEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, TutorialModel.LEVEL1_CLICK_ON_SECOND_PET);
                tutorial.showFocusArrow(490, 180, 90);
                tutorial.showBlockingSpotlight(300, 220, 0.8);
                sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_clean");
            };
        }
        public function onClickOnReception(_arg1:Event=null):void{
            if (tickModel.pause){
                tickModel.pause = false;
            };
            eventMap.unmapListener(eventDispatcher, EventConstants.HANDLE_NEXT_IN_QUEUE, this.onClickOnReception);
            eventMap.unmapListener(eventDispatcher, EventConstants.FIRST_PET_BUBBLE_CLOSED, onMappedEvent);
            mapEvent(EventConstants.SHOW_COMPUTER_DISPLAY, TutorialModel.LEVEL1_SELECT_PATIENT);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"80_machine_cleaned"}));
            tutorial.showFocusArrow(380, 360, 90);
            tutorial.showBlockingSpotlight(190, 400, 0.7);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_clickonreception");
        }
        public function onSelectPatient():void{
            mapEvent(EventConstants.ON_COMPUTER_DISPLAY_HIDDEN, TutorialModel.LEVEL1_WELCOME_PATIENT_2);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"90_cl_reception"}));
            tutorial.showFocusArrow(230, 180, -90);
            tutorial.showBlockingSpotlight(500, 135, 1.2);
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onWelcomePatient2():void{
            mapEvent(EventConstants.ON_ARRIVAL_AT_RECEPTION, TutorialModel.LEVEL1_WELCOME_PATIENT_3);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"100_reception_closed"}));
            tutorial.hideFocusArrow();
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
        }
        public function onWelcomePatient3():void{
            tutorial.showFocusArrow(0xFF, 220);
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
            sunModel.simpleMessage = languageModel.getTextByKey("general_tutorial_welcomepatient2");
            mapEvent(EventConstants.BUBBLE_CLOSED, TutorialModel.LEVEL1_WELCOME_PATIENT_4);
        }
        public function onWelcomePatient4():void{
            dispatch(new InfoEvent(EventConstants.SHOW_MAIN_MENU, null));
            dispatch(new InfoEvent(EventConstants.DISABLE_FRIENDS_MENU, null));
            gameViewModel.gameViewPosition = new Point(gameViewModel.gameViewPosition.x, -160);
            mapEvent(EventConstants.HIDE_VIEW, TutorialModel.LEVEL1_PATIENT_IN_TREATMENT);
            onRemoveOverlay();
        }
        public function onPetInTreatment():void{
            mapEvent(EventConstants.ON_TREATMENT_STARTED, TutorialModel.LEVEL1_BOOST_PATIENT);
            eventMap.mapListener(eventDispatcher, EventConstants.ON_TREATMENT_FINISHED, mapTreatmentFinished);
            tutorial.showFocusArrow(340, 310, 180);
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
            eventMap.mapListener(eventDispatcher, EventConstants.HIGHLIGHT_MACHINES, onBatterieNeeded);
            eventMap.mapListener(eventDispatcher, SlotMachineEvent.START_ROLLING, mapClickOnSlotmachine);
        }
        public function onBoostPatient():void{
            var _local1:TreatmentMachineVO;
            var _local2:IMachine;
            var _local3:Object;
            eventMap.unmapListener(eventDispatcher, EventConstants.HIGHLIGHT_MACHINES, onBatterieNeeded);
            mapEvent(EventConstants.BOOST_MACHINE, TutorialModel.LEVEL1_BOOST_PATIENT_FINISH);
            for each (_local2 in world.machines) {
                if (_local2.type == GameConstants.TYPE_TREATMENT_GENERAL){
                    _local1 = (_local2 as TreatmentMachineVO);
                    break;
                };
            };
            _local3 = {label:"iconButton/button/label", key:"global_boost"};
            _local1.showSpeechBubble(SpeechBubbleConstants.TYPE_BOOST_BUBBLE, _local3);
            tutorial.showFocusArrow(340, 310, 180);
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
            sunModel.simpleMessage = languageModel.getTextByKey("general_tutorial_useboost");
        }
        public function onBoostPatientEnd():void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"108_boost"}));
            triggerNewState(TutorialModel.LEVEL1_FINISH_LEVEL1_TUTORIAL, 1);
            tutorial.hideFocusArrow();
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onFinish():void{
            gameStateModel.state = GameStateModel.STATE_GAME_RUNNING;
            eventMap.unmapListener(eventDispatcher, EventConstants.ON_TREATMENT_FINISHED, mapTreatmentFinished);
            eventMap.unmapListener(eventDispatcher, EventConstants.BOOST_MACHINE, onMappedEvent);
            onRemoveOverlay();
            enableControls();
        }
        private function getAvatarPosition(_arg1:int):Point{
            var _local2:Slot = roomSlotsModel.getSlotById(_arg1);
            var _local3:Point = new Point();
            _local3.x = (_local2.position.x + (GameConstants.ROOM_WIDTH / 2));
            _local3.y = ((_local2.position.y + GameConstants.ROOM_HEIGHT) + AVATAR_OFFSET_FIRST_STEPS);
            return (_local3);
        }
        private function onFirstPetClosed(_arg1:Event=null):void{
            tutorial.hidePetComponent();
            if (tutorialModel.state != TutorialModel.LEVEL1_CURED_FIRST_PET){
                tutorial.hideSpotlight();
            };
            dispatch(new InfoEvent(EventConstants.FIRST_PET_BUBBLE_CLOSED, null));
        }

    }
}//package net.wooga.pets.views.tutorial.chapter 
